/*
 *  EventLib
 *  qEventHandler.h
 *
 *	Copyright (c) 2011, AVS
 *	All rights reserved.
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions are met:
 *	1.	Redistributions of source code must retain the above copyright
 *		notice, this list of conditions and the following disclaimer.
 *	2.	Redistributions in binary form must reproduce the above copyright
 *		notice, this list of conditions and the following disclaimer in the
 *		documentation and/or other materials provided with the distribution.
 *	3.	All advertising materials mentioning features or use of this software
 *		must display the following acknowledgement:
 *		This product includes software developed by the AVS.
 *	4.	Neither the name of the AVS nor the
 *		names of its contributors may be used to endorse or promote products
 *		derived from this software without specific prior written permission.
 *
 *	THIS SOFTWARE IS PROVIDED BY AVS ''AS IS'' AND ANY
 *	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *	DISCLAIMED. IN NO EVENT SHALL AVS BE LIABLE FOR ANY
 *	DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef _qEvent_h
#define _qEvent_h

#include "EventLib.h"

enum EVENT_TYPE
{
	DEFAULT_EVENT = 0,
	KEY_EVENT,
	MOUSE_EVENT,
	GAME_EVENT
};

enum KEY_TYPE
{
	DOWN = 0,
	UP
};

typedef struct KeyEvent
{
	int key;
	KEY_TYPE state;
} KeyEvent;

typedef struct MouseEvent
{
	int x, y;
} MouseEvent;

typedef struct GameEvent
{
	void *data;
} GameEvent;

typedef union EventData
{
	KeyEvent key;
	MouseEvent mouse;
	GameEvent game;
} EventData;

typedef struct EventState
{
	KeyEvent key;
	MouseEvent mouse;
	GameEvent game;
} EventState;

class qEvent : public iScriptable<qEvent>
{
public:
	qEvent();
	qEvent(std::string _name);
	qEvent(int _key, KEY_TYPE _state, EVENT_TYPE _type = KEY_EVENT);
	qEvent(int _x, int _y, EVENT_TYPE _type = MOUSE_EVENT);
	qEvent(void *data, EVENT_TYPE _type = GAME_EVENT);
	~qEvent();
	
	int get_key_code();
	KEY_TYPE get_key_state();
	
	int get_mouse_x() { return this->data.mouse.x; }
	int get_mouse_y() { return this->data.mouse.y; }
	
	void *get_game_data() { return this->data.game.data; }
	
	std::string &getName() { return this->name; }
	virtual EVENT_TYPE getType() { return this->type; }
	
	void REGISTER_SCRIPTABLES(qScriptEngine *engine);
private:
	std::string name;
	EVENT_TYPE type;
	EventData data;
};

#endif